package com.pan.server.controller.Admin;

import com.pan.common.result.Result;
import com.pan.pojo.dto.BookAddDTO;
import com.pan.pojo.dto.In;
import com.pan.pojo.entity.Book;
import com.pan.server.service.BooksService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/adminBook")
@Slf4j
@Api(tags = "管理书籍控制器")
@RestController
@CrossOrigin("http://localhost:7070")
public class AdminBooksController {

    @Autowired
    private BooksService booksService;


    /**
     * 添加书籍
     * @param bookAddDTO
     * @return
     */
    @PostMapping(value = "/addBook")
    @ApiOperation("书籍添加")
    public Result<String> addBook(@RequestBody BookAddDTO bookAddDTO){
        log.info("书籍添加...", bookAddDTO);

        booksService.addBook(bookAddDTO);

        return Result.success("书籍添加成功");
    }

    /**
     *
     * @param in
     * @return
     */
    @PostMapping(value = "/deleteBook")
    @ApiOperation("书籍删除")
    public Result<String> deleteBook(@RequestBody In in){
        log.info("书籍删除...", in.getOrderId());

        booksService.deleteBook(in.getOrderId());

        return Result.success("书籍删除成功");
    }

    @PostMapping(value = "/updateBook")
    @ApiOperation("书籍更新")
    public Result<String> updateBook(@RequestBody Book book){
        log.info("书籍更新...", book);

        booksService.updateBook(book);

        return Result.success("书籍更新成功");
    }

}